package main.Q1501_1600;

import java.util.Arrays;

public class Q1501_1510 {
    public static void main(String[] args) {
        System.out.println("Question1501：");
        System.out.println("Question1502：判断能否形成等差数列");
        System.out.println("Question1503：");
        System.out.println("Question1504：");
        System.out.println("Question1505：");
        System.out.println("Question1506：");
        System.out.println("Question1507：");
        System.out.println("Question1508：子数组和排序后的区间和");
        int[] nums={1,2,3,4};
        System.out.println(new Question1508().rangeSum(nums,4,1,10));
        System.out.println("Question1509：");
        System.out.println("Question1510：");
    }
}

class Question1502{
    public boolean canMakeArithmeticProgression(int[] arr) {
        Arrays.sort(arr);
        int value=arr[1]-arr[0];
        for (int i=2;i<arr.length;i++){
            if (arr[i]-arr[i-1]!=value) return false;
        }
        return true;
    }
}

class Question1508{
    public int rangeSum(int[] nums, int n, int left, int right) {
        int sum=0,length= nums.length,j=1;
        int[] sumArr=new int[(length*(length+1))/2+1],priArr=new int[length];
        for (int i=0;i<length;i++){//前缀和
            if (i==0) priArr[i]=nums[i];
            else priArr[i]=priArr[i-1]+nums[i];
            for (int k=0;k<i;k++){
                sumArr[j++]=priArr[i]-priArr[k];
            }
            sumArr[j++]=priArr[i];
        }
        Arrays.sort(sumArr);
        final int mod=(int)1e9+7;
        for (int i=left;i<=right;i++){
            sum=(sum+sumArr[i])%mod;
        }
        return sum;
    }
}